package com.chaoyong.higo.activity;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.entity.StringEntity;
import org.json.JSONException;
import org.json.JSONObject;

import com.chaoyong.higo.R;
import com.chaoyong.higo.adapter.GoodsExceptAdapter;
import com.chaoyong.higo.adapter.ProtailAdapter;
import com.chaoyong.higo.base.BaseActivity;
import com.chaoyong.higo.bean.ExceptBean;
import com.chaoyong.higo.bean.UserListBean;
import com.chaoyong.higo.net.OApi;
import com.chaoyong.higo.utils.EmptyUtil;
import com.chaoyong.higo.utils.V;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.view.TitleView;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

public class SeleCounActivity extends BaseActivity {
	
	@Override
	public int layoutResID() {
		return R.layout.activity_select_count;
	}
	private Context context;
	private TitleView titleView;
	private GridView recyclerView;
	private GoodsExceptAdapter adapter;
	private String goodsId;
	
	
	@Override
	public void findView() {
		titleView=V.f(this, R.id.selecoun_title);
		recyclerView=V.f(this, R.id.freghome_new_recyclerview);
	}

	@Override
	public void init() {
		context=this;
		titleView.setTitleText("选择期数",context.getResources().getColor(R.color.home_text));
		titleView.setLeftImage(R.drawable.back_red);
		titleView.setonLeftClinck(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		goodsId = getIntent().getStringExtra("goods_id");
		showToast(goodsId);
		adapter = new GoodsExceptAdapter(this);
		recyclerView.setAdapter(adapter);
	}
	
	
	@Override
	public void onClick(View v) {
		
	}
	
	@Override
	protected void onStart() {
		super.onStart();
//		httpQueryGoodsExcept(goodsId);
	}
	
	
	private void httpQueryGoodsExcept(String goodsId){
		HttpUtils utils = new HttpUtils();
		RequestParams params = new RequestParams();
		JSONObject object = new JSONObject();
		try {
			object.put("goods_id", goodsId);
			params.setBodyEntity(new StringEntity(object.toString(), "UTF-8"));
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		// param.setBodyEntity(new StringEntity(jsonObject.toString(),
		// "UTF-8"));
		utils.send(HttpMethod.POST, OApi.appport_getGoodsDatail, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {

			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				Gson gson = new Gson();
				ExceptBean bean = gson.fromJson(arg0.result, ExceptBean.class);
				if (bean.getStatus().equals("1")) {
					List<ExceptBean.DataEntity> e = bean.getData();
					if (!EmptyUtil.isEmpty(e)) {
						adapter.setList(e);
					}
				}
			}

		});
	}
	

}
